//
//  Notifycation.swift
//  ShareUmbrella
//
//  Created by niupark on 2017/10/10.
//  Copyright © 2017年 尧尚信息科技. All rights reserved.
//

import Foundation

enum NotifyType :Int {
    case type1 = 1
    case type2 = 2
    case type3 = 3
    case type4 = 4
    case type5 = 5
}

public let RomoteNotifcation = Notification.Name(rawValue: "ShareUmbrella.RomoteNotifcation")

let RomoteNotify = RemoteNotifyManager.sharedInstance

class RemoteNotifyManager: NSObject {
    static let sharedInstance = RemoteNotifyManager()
    
    private override init() {
        super.init()
    }
    
    func startup(){
        self.listenNotification()
    }
    
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
    func listenNotification(){
        NotificationCenter.default.addObserver(self, selector: #selector(handleNotify(notification:)), name: RomoteNotifcation, object: nil)
    }
    
    func handleNotify(notification: Notification){
        guard let info = notification.userInfo, let iType = info["type"] as? NSNumber  else{
            return
        }
        
        
        guard let type = NotifyType(rawValue: iType.intValue) else{
            return
        }
        switch type {
        case .type1:
            break
        case .type2, .type3:
            guard let _ = APP.currentVC as? HelperVC else {
                APP.currentVC?.ys.push(HelperVC())
                break
            }
        case .type4:
            guard let _ = APP.currentVC as? RecipientsVC else {
                APP.currentVC?.ys.push(RecipientsVC())
                break
            }
        case .type5:
            guard let _ = APP.currentVC as? RecipientsResultVC else {
                APP.currentVC?.ys.push(RecipientsResultVC(), animated: true, withdata: info["param1"] as! String)
                break
            }
        }
        
        
    }
    
}
